import http from '@/http';
import type {Collect, ResponseData} from '@/types/interface';

const collectApi = {
    // 收藏帖子
    collectPost: (postId: number): Promise<ResponseData<boolean>> => {
        return http.post('/collect/add', { postId });
    },

    // 取消收藏
    cancelCollect: (postId: number): Promise<ResponseData<boolean>> => {
        return http.post('/collect/cancel', { postId });
    },

    // 获取用户收藏列表
    getUserCollects: (userId: number, page: number, size: number): Promise<ResponseData<{
        list: Collect[];
        total: number;
    }>> => {
        return http.get(`/collect/list?userId=${userId}&page=${page}&size=${size}`);
    },

    // 检查是否已收藏
    checkCollect: (postId: number): Promise<ResponseData<{ isCollect: boolean }>> => {
        return http.get(`/collect/check?postId=${postId}`);
    }
};

export default collectApi;